import { QueryDescriptor, ValuePredicateFn } from '~/core/dsl';
import { EngineCapability, EngineCapabilityHint, RuleContext } from 'qvog-dsl';

export type QEngineCapability = EngineCapability<QHint>;
export type QRuleContext = RuleContext<QHint>;

export interface QHint extends EngineCapabilityHint {
    options: {
        name: string;
    };
    native: QNative;
    issueTemplate: QIssueTemplate;
}

export interface QNative {
    context: {
        /**
         * Current native query handler.
         */
        descriptor: QueryDescriptor;
    };
    api: {
        nodes(predicate: ValuePredicateFn, alias?: string): string;
        predicate(predicate: ValuePredicateFn, alias?: string): string;
    };
}

export interface QIssueTemplate {
    message: string;
}

export function getRandomString(length: number): string {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';
    const charactersLength = characters.length;
    for (let i = 0; i < length; i++) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
}
